package recipe;

import java.util.ArrayList;

/**
 * Class - RecipeData
 * Description - Abstract representation of a recipe
 * 
 * @author Ryne Okimoto
 */

public class RecipeData {

	// Class data
	private String recipeName = null;
	private String imageFileName = null;
	private String category = null;

	// For first iteration
	// Ingredients and instructions are simple concatenated strings
	private String ingredients = null;
	private String instructions = null;
	private String stringOfTags = null;

	// Implement later for better program structure
	private ArrayList<Ingredient> listOfIngredients;
	
	// TODO private ArrayList<String> listOfTags;
	
	/**
	 * Default constructor
	 */
	public RecipeData(){
		recipeName = "";
		imageFileName = "";
		ingredients = "";
		instructions = "";
		category = "";
		stringOfTags ="";
		listOfIngredients = new ArrayList<Ingredient>();

	} // constructor
	
	/**
	 * Method - getRecipeName
	 * Description - getter for recipeName
	 * @return String
	 */
	public String getRecipeName(){
		return recipeName;
	}
	
	/**
	 * Method - setRecipeName
	 * Description - setter for recipeName
	 * @return void
	 */
	public void setRecipeName(String recipeName){
		this.recipeName = recipeName;
	}
	
	/**
	 * Method - getImageFileName
	 * Description - getter for imageFileName
	 * @return String
	 */
	public String getImageFileName(){
		return imageFileName;
	}
	
	/**
	 * Method - setImageFileName
	 * Description - setter for imageFileName
	 * @param imageFileName
	 */
	public void setImageFileName(String imageFileName){
		this.imageFileName = imageFileName;
	}
	
	/**
	 * Method - getCategory
	 * Description - getter for category
	 * @return String
	 */
	public String getCategory(){
		return this.category;
	}
	
	/**
	 * Method - setCategory
	 * Description - setter for category
	 * @param category
	 */
	public void setCategory(String category){
		this.category = category;
	}
	
	/**
	 * Method - addIngredient
	 * Description - adds an ingredient to the list of ingredients
	 * @param name
	 * @param amount
	 * @param unit
	 * @return boolean
	 */
	public boolean addIngredient(String name, String amount, String unit){
		boolean isUnitOK = Ingredient.validateUnit(unit);
		double amountValue = Ingredient.parseAmount(amount);
		
		if(isUnitOK && amountValue > 0){
			listOfIngredients.add(new Ingredient(name, amount, unit));
		}
		
		return isUnitOK && amountValue > 0;
	}
	
	/**
	 * Method - getListOfIngredients
	 * Description - Returns a string array containing all ingredients
	 * @return String[]
	 */
	public String getListOfIngredients(){
		Ingredient temp = null;
		StringBuilder ingredientString = new StringBuilder();
		
		for(int i = 0; i < listOfIngredients.size(); i++){
			temp = listOfIngredients.get(i);
			ingredientString.append(temp.getAmount() + " " 
					+ temp.getUnit() + " " 
					+ temp.getIngredientName() + "\n");
		}
		
		
		return ingredientString.toString();
	}
	
	/**
	 * Method - setListOfIngredients
	 * Description - Takes a string that consists of ingredients separated by newlines
	 * and splits it into separate ingredient strings.  The ingredient strings are 
	 * split into the name, amount, and unit. The ingredient is added to the list. 
	 * @param ingredients_string
	 * @return void
	 */
	public void setListOfIngredients(String ingredients_string){
		String[] ingredients_array = ingredients_string.split("\\n");
		String[] temp_ingredient = null;
		
		for(int i = 0; i < ingredients_array.length; i++){
			temp_ingredient = ingredients_array[i].split(" ");
			this.addIngredient(temp_ingredient[2], temp_ingredient[0], temp_ingredient[1]);
		}
	}
	
	/**
	 * Method - getIngredients
	 * Description - getter for ingredients
	 * @return String
	 */
	public String getIngredients(){
		return ingredients;
	}
	
	/**
	 * Method - setIngredients
	 * Description - setter for ingredients
	 * @return void
	 * @param String
	 */
	public void setIngredients(String ingredients){
		this.ingredients = ingredients;
	}
	
	/**
	 * Method - getInstructions
	 * Description - getter for instructions
	 * @return String
	 */
	public String getInstructions(){
		return instructions;
	}
	
	/**
	 * Method - setInstructions
	 * Description - setter for instructions
	 * @return void
	 * @param String
	 */
	public void setInstructions(String instructions){
		this.instructions = instructions;
	}
	
	/**
	 * Method - getTags
	 * Description - getter for tags
	 * Notes - Initial implementation using a String not a list
	 * @return String
	 */
	public String getTags(){
		return this.stringOfTags;
	}
	
	/**
	 * Method - setTags
	 * Description - setter for tags
	 * Notes - Initial implementation using a String
	 * @param stringOfTags
	 */
	public void setTags(String stringOfTags){
		this.stringOfTags = stringOfTags;
	}
	
	/**
	 * convertUnits
	 * Description: Method to convert units from metric to standard and standard to metric
	 * @param none
	 * @return boolean
	 */
	//TODO
	public boolean convertUnits(){
		boolean conversionOK = false;
		
		return conversionOK;
	} // convertUnits
	
	/**
	 * Method - scaleAmount
	 * Description - 
	 */
	//TODO
	public boolean scaleAmount(int scaleFactor){
		boolean scaleOK = false;
		
		return scaleOK;
	} // scaleAmount
	
} // class
